/*
 * @Author: shenya
 * @Date: 2023-09-11 16:12:28
 * @Description: 发布动态option
 */
import {
  VOTE_STATUS_DIC,
  VOTE_RESULT_DIC,
  VOTE_TYPE_DIC,
  VOTE_STATUS,
} from '@/const/type';

export const dynamicOption = (isEdit, isBase) => {
  console.log('dynamicOption', isEdit);
  console.log('isBase', isBase);
  return {
    submitBtn: false,
    emptyBtn: false,
    labelWidth: 120,
    column: [
      {
        label: '关联账号',
        prop: 'name',
        row: true,
        span: 24,
        type: 'select',
        formslot: true,
        filterable: true,
        rules: [
          {
            required: true,
            message: '请选择关联账号',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '标签',
        prop: 'tag',
        span: 24,
        row: true,
        formslot: true,
        rules: [
          {
            required: true,
            message: '请选择标签',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '图片/视频',
        prop: 'image',
        type: 'upload',
        listType: 'picture-card',
        fileSize: 50 * 1024,
        span: 24,
        row: true,
        oss: 'qiniu',
        propsHttp: {
          name: 'hash',
          url: 'key',
        },
        props: {
          label: 'name',
          value: 'url',
        },
        accept: '.mp4, .mpeg, .WMV, .mov, .jpg, .png, .jpeg, .webp, .heic',
        tip: '最多可上传30个图片/视频',
        limit: 30,
        drag: true,
        multiple: true,
        rules: [
          {
            required: true,
            message: '请选择图片/视频',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '动态标题',
        prop: 'title',
        maxlength: 20,
        span: 24,
        display: !isBase,
        row: true,
        rules: [
          {
            required: true,
            message: '请输入动态标题',
            trigger: 'blur',
          },
        ],
      },
      // {
      //   label: '关联话题',
      //   prop: 'topic',
      //   span: 24,
      //   row: true,
      //   formslot: true,
      // },
      {
        label: '动态内容',
        prop: 'content',
        type: 'textarea',
        row: true,
        span: 24,
        maxlength: 2000,
        formslot: true,
        rules: [
          {
            required: true,
            message: '请输入动态内容',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '发起投票',
        prop: 'voteStatus',
        type: 'radio',
        row: true,
        labelTip: '若发起投票，建议上传图片为横图，展示效果更佳',
        display: isBase,
        detail: isEdit,
        border: false,
        dicData: VOTE_STATUS_DIC,
        value: VOTE_STATUS.NO,
        rules: [
          {
            required: true,
            message: '请选择是否发起投票',
            trigger: 'blur',
          },
        ],
        control: (val, form) => {
          console.log('vvv', val);
          if (val === VOTE_STATUS.NO) {
            return {
              voteType: {
                display: false,
              },
              voteResultType: {
                display: false,
              },
              voteEndTime: {
                display: false,
              },
              voteTitle: {
                display: false,
              },
              voteDescription: {
                display: false,
              },
              viewpoints: {
                display: false,
              },
            };
          } else {
            console.log('进来了麻');
            return {
              voteType: {
                display: true,
              },
              voteResultType: {
                display: true,
              },
              voteEndTime: {
                display: true,
              },
              voteTitle: {
                display: true,
              },
              voteDescription: {
                display: true,
              },
              viewpoints: {
                display: true,
              },
            };
          }
        },
      },
      {
        label: '类型',
        prop: 'voteType',
        type: 'radio',
        border: false,
        labelTip: '投票内容将在动态正文下方展示',
        detail: isEdit,
        display: false,
        row: true,
        dicData: VOTE_TYPE_DIC,
        value: '2',
        rules: [
          {
            required: true,
            message: '请选择类型',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '投票结果',
        prop: 'voteResultType',
        type: 'radio',
        row: true,
        span: 24,
        display: false,
        border: false,
        dicData: VOTE_RESULT_DIC,
        value: '2',
        rules: [
          {
            required: true,
            message: '请选择投票结果是否可见',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '投票结束时间',
        prop: 'voteEndTime',
        type: 'datetime',
        detail: isEdit,
        display: false,
        format: 'yyyy-MM-dd HH:mm:ss',
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        pickerOptions: {
          disabledDate: (time) => {
            return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
          },
        },
        rules: [
          {
            required: true,
            message: '请选择结束时间',
          },
        ],
      },
      {
        label: '标题',
        prop: 'voteTitle',
        display: false,
        span: 24,
        rules: [
          {
            required: true,
            message: '请输入标题，不超过30个字',
          },
          {
            min: 2,
            max: 30,
            message: '长度在 2 到 30 个字符',
            trigger: 'blur',
          },
        ],
      },
      {
        label: '',
        prop: 'viewpoints',
        formslot: true,
        display: false,
        span: 24,
      },
      {
        label: '结语',
        prop: 'voteDescription',
        type: 'textarea',
        row: true,
        display: false,
        span: 24,
        maxlength: 200,
        rules: [
          {
            required: true,
            message: '请输入结语，不超过200个字',
            trigger: 'blur',
          },
        ],
      },
    ],
  };
};
//置顶时间
export const topTimeOption = () => {
  return {
    submitBtn: false,
    emptyBtn: false,
    labelWidth: 120,
    column: [
      {
        label: '置顶结束时间',
        prop: 'topTime',
        type: 'datetime',
        format: 'yyyy-MM-dd HH:mm:ss',
        span: 18,
        valueFormat: 'yyyy-MM-dd HH:mm:ss',
        pickerOptions: {
          disabledDate: (time) => {
            return time.getTime() < Date.now() - 24 * 60 * 60 * 1000;
          },
        },
        rules: [
          {
            required: true,
            message: '请选择结束时间',
          },
        ],
      },
    ],
  };
};
//投票记录
export const voteRecordOption = () => {
  return {
    ...window.$crudMixins.tableOptions,
    addBtn: false,
    editBtn: false,
    delBtn: false,
    menu: false,
    column: [
      {
        label: '投票者',
        prop: 'voter',
        formslot: true,
      },
      {
        label: '用户编号',
        prop: 'userCode',
      },
      {
        label: '投票时间',
        prop: 'createTime',
      },
    ],
  };
};
